<?php

require_once dirname(__FILE__) . '/TestCase.php';

class Auth_Vidoop_Secure_EnrollmentAPITest extends Auth_Vidoop_Secure_TestCase {

	public function testAPICall() {
		$service = $this->get_service('enrollment');
		$categories = $service->get_category();

		// verify categories
		$this->assertGreaterThan(0, sizeof($categories));
		$this->assertNotNull($categories[0]->id);
		$this->assertNotNull($categories[0]->name);
		$this->assertGreaterThan(0, sizeof($categories[0]->images));
		$this->assertNotNull($categories[0]->images[0]->uri);
		$image_uri_base = $this->config['base'] . '/vs/categories/' . $categories[0]->id . '/representative_images/';
		$this->assertRegExp('/' . preg_quote($image_uri_base, '/') . '.+/', $categories[0]->images[0]->uri);

		// verify that retrieval of a single category matches with above results
		$cat_id = $categories[0]->id;
		$first_category = $service->get_category($cat_id);
		$this->assertEquals($categories[0], $first_category);

		// verify that retrieval of a single category's images matches with above results
		$images = $service->get_category_images($cat_id);
		$this->assertGreaterThan(0, sizeof($images));
		$this->assertNotNull($images[0]->uri);
		$this->assertEquals($categories[0]->images, $images);
	}

	public function testRandomBundle() {
		$service = $this->get_service('enrollment');

		// random bundle
		$bundle = $service->get_random_bundle(6);
		$this->assertEquals(6, sizeof($bundle));

		// random bundle with specified categories
		$bundle = $service->get_random_bundle(9, array('outspac1', 'airplns1'));
		$this->assertEquals(9, sizeof($bundle));
		$this->assertEquals('outspac1', $bundle[0]);
		$this->assertEquals('airplns1', $bundle[1]);
	}
}
